package org.example.agent.task;

import org.example.dto.TaskStatus;
import org.example.enums.EJobType;
import org.example.enums.ETaskErrCode;
import org.example.enums.ITaskStep;
import org.example.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ParentTask {

    private static final Logger LOGGER = LoggerFactory.getLogger(ParentTask.class);

    protected Result<TaskStatus> handleResult(Result<TaskStatus> paramResult, ETaskErrCode eTaskErrCode) {
        if (paramResult == null) {
            Result<TaskStatus> rs = Result.error().addError(eTaskErrCode.getErrCode(), eTaskErrCode.getErrorMsg());
            rs.setResult(new TaskStatus());
            return rs;
        } else {
            if (paramResult.getResult() == null) {
                paramResult.setResult(new TaskStatus());
            }
            return paramResult;
        }
    }

    protected void printErrMsg(Result<String> result, EJobType jobType, ITaskStep taskStep) {
        if (!result.isSuccess()) {
            LOGGER.error("jobType:{} taskStep:{} 状态上报 error, errorMsg:{}", jobType.getJobName(), taskStep.getStep(), result.getMessage());
        }
    }
}
